package logic

import (
	"context"
	"week2_zg6/bookRpc/book"

	"week2_zg6/bookApi/internal/svc"
	"week2_zg6/bookApi/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type SearcherLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewSearcherLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearcherLogic {
	return &SearcherLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *SearcherLogic) Searcher(req *types.SearcherRequest) (resp *types.Response, err error) {
	searcher, err := l.svcCtx.Book.Searcher(context.Background(), &book.SearcherRequest{
		Searcher: req.Searcher,
	})
	if err != nil {
		return nil, err
	}
	return &types.Response{
		Id:       searcher.Id,
		BookName: searcher.BookName,
		Author:   searcher.Author,
		Class:    searcher.Class,
		Title:    searcher.Title,
	}, nil
}
